import { Http } from "../../utils/http"
import { Card } from "../../model/Card"

const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    gradientColor: {
      '0%': '#ff40be',
      '100%': '#ff4056',
    },
    show: false,
    cardId: '',
    resList: [],
    hedd: true,
    carQr: '',
    headerImage: '',
  },

  //生命周期函数--监听页面加载  
  //接收卡片ID
  onLoad: async function (options) {
    //console.log(options.cardId);
    this.setData({
      cardId: options.cardId
    });
    this.cardQrcodeList();
    this.cardQrcode();
  },

  //获取会员已购买 - 卡 - 订单详情页
  cardQrcodeList: async function () {
    let result = await Card.get_card_detail_by_id(this.data.cardId);
    console.log(result.data);
    console.log("*****");
    if (result.code == 0) {
      this.setData({
        resList: result.data,
        headerImage: result.data.product.headerimages,
      })
      wx.stopPullDownRefresh();
    } else {
      console.log(result);
    }
  },

  //获取卡码
  cardQrcode: async function () {
    let result = await Card.get_card_qrcode(this.data.cardId);
    if (result.code == 0) {
      this.setData({
        carQr: app.Url + result.data
      })
    } else {
      console.log(result.msg);
    }
  },
  showPopup() {
    this.setData({ show: true, hedd: false });
  },
  onClose() {
    this.setData({ show: false, hedd: true });
  },
  onPullDownRefresh: function () {
    // 页面相关事件处理函数--监听用户下拉动作
    this.cardQrcodeList();
  }

})